﻿using CodeSaude.Domain.Interfaces.Specification;
using CodeSaude.Domain.Interfaces.Validation;

namespace CodeSaude.Domain.Validation.Base {
    public class Regra<T> : IRegra<T> where T : class {
        private readonly ISpecification<T> _specificationRule;
        public string MensagemErro { get; private set; }

        public Regra(ISpecification<T> rule, string mensagemErro) {
            this._specificationRule = rule;
            this.MensagemErro = mensagemErro;
        }

        public bool Validar(T entity) {
            return this._specificationRule.IsSatisfiedBy(entity);
        }
    }
}
